// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import  axios  from  'axios'
import ElementUI from 'element-ui';
import md5 from 'js-md5'; 
import 'element-ui/lib/theme-chalk/index.css';
import router from './router'
Vue.use(ElementUI);
Vue.config.productionTip = false
Vue.prototype.$md5 = md5;
///request拦截器
axios.interceptors.request.use(config   =>  {
  //向请求头添加token
  debugger
  const date =  Date.parse(new Date())
  if (config.method == 'post') {
    config.headers.post['X-Access-Token'] = md5('04d2b9c8e69d11ebba5700ff9c30bc21,' + date)
    config.data = {
      ...config.data,
    }
    config.url = config.url+ `?_time=${date}`
  } else if (config.method == 'get') {
    config.headers.get['X-Access-Token'] = md5('04d2b9c8e69d11ebba5700ff9c30bc21,' + date)
    config.params = {
      ...config.params,
      _time: date,
      
    }
  }else if (config.method == 'delete') {
    config.headers.delete['X-Access-Token'] = md5('04d2b9c8e69d11ebba5700ff9c30bc21,' + date)
    config.url = config.url+ `&_time=${date}`
  }else if (config.method == 'put') {
    debugger
    config.headers.put['X-Access-Token'] = md5('04d2b9c8e69d11ebba5700ff9c30bc21,' + date)
    // config.headers.common['Content-Type'] = 'application/x-www-form-urlencoded'
    config.headers.put['Content-Type'] = 'application/x-www-form-urlencoded'
    config.params = {
      ...config.params,
      _time: date,
      
    }
    // config.url = config.url+ `?_time=${date}`
  }
  return config ;
}, error =>  {
  return Promise.reject(error);
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
